package com.xj.zhihudemo.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Xujing on 16/8/9.
 */
public abstract class BaseActivity extends AppCompatActivity {

    protected final String TAG = this.getClass().getSimpleName();
    protected Activity mContext;

    private Unbinder mUnbinder;
    private String APP_NAME;
    private boolean isFirstShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(getLayoutID());
        mUnbinder = ButterKnife.bind(this);
        initData();
        initView(savedInstanceState);

    }

    @Override
    protected void onResume() {

        if (isFirstShow) {
            isFirstShow = false;
            initData();
        }
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mUnbinder.unbind();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    protected abstract int getLayoutID();

    /**
     * @param savedInstanceState 初始化视图
     */
    protected abstract void initView(Bundle savedInstanceState);

    /**
     * 初始化话数据
     */
    protected abstract void initData();

}

